<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<link href="/static/mall/css/bootstrap-modal.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet">
<head th:replace="mall/header::head-fragment('首页','index')">
</head>
<body>
<header th:replace="mall/header::header-fragment"></header>
<content id="content">
    <nav th:replace="mall/header::nav-fragment"></nav>
    <div id="banner">
        <div class="goods_item center">
            <!--
            <div class="main center">
                <th:block th:if="${#lists.isEmpty(products)}">
                    <img style="margin-top: 16px;padding: 16px 20px;" th:src="@{/mall/image/null-content.png}">
                </th:block>
                <th:block th:unless="${#lists.isEmpty(products)}">
                    <th:block th:each="product : ${products}">
                        <div class="item_card_frame">
                            <div class="item_card"><a th:href="@{'/goods/detail/'+${goods.goodsId}}" target="_blank"><img
                                    th:src="@{${goods.goodsCoverImg}}" th:alt="${product.getProductName()}"></a></div>
                            <div class="item_brand"><a th:href="@{'/goods/detail/'+${goods.goodsId}}" target="_blank"
                                                       th:text="${goods.goodsName}">newbee.ltd</a></div>
                            <div class="item_sub_intro" th:text="${goods.goodsIntro}">newbee.ltd</div>
                            <div class="item_price" th:text="${goods.sellingPrice+'.00元'}">1299.00元</div>
                        </div>
                    </th:block>
                </th:block>
                <div class="clear"></div>
            </div>
            -->
            <!--
            <div class="pages">
                <div class="page_wrap">
                    <th:block th:if="${null != pageResult and !#lists.isEmpty(pageResult.list)}">
            <span class="page_span1">
                 <a th:href="@{${pageResult.currPage==1}?'##':'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage-1}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}">
                                    < 上一页
                                </a>
                <th:block th:if="${pageResult.currPage-2 >=1}"><a
                        th:href="@{'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage-2}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}"
                        th:text="${pageResult.currPage -2}">1</a></th:block>
                <th:block th:if="${pageResult.currPage-1 >=1}"><a
                        th:href="@{'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage-1}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}"
                        th:text="${pageResult.currPage -1}">1</a></th:block>
                <a href="##" class="active" th:text="${pageResult.currPage}">1</a>
                <th:block th:if="${pageResult.currPage+1<=pageResult.totalPage}"><a
                        th:href="@{'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage+1}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}"
                        th:text="${pageResult.currPage +1}">1</a></th:block>
                <th:block th:if="${pageResult.currPage+2<=pageResult.totalPage}"><a
                        th:href="@{'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage+2}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}"
                        th:text="${pageResult.currPage +2}">1</a></th:block>
                 <a th:href="@{${pageResult.currPage>=pageResult.totalPage}?'##':'/search?keyword='+${keyword==null?'':keyword}+'&page=' + ${pageResult.currPage+1}+'&goodsCategoryId='+${goodsCategoryId==null?'':goodsCategoryId}+'&orderBy='+${orderBy==null?'':orderBy}}">
                                    下一页 >
                                </a>
					</span>
                    </th:block>
                </div>
            </div>
            -->
        </div>
    <div id="recommend">
        <h2>为商品信息：</h2>
        <ul>
            <th:block th:unless="${#lists.isEmpty(products)}">
                <th:block th:each="product : ${products}">
                    <li>
                        <a>
                            <p class="info" th:text="${product.getProductName()}">产品名称</p>
                            <p class="info" th:text="${product.getProductIntro()}">产品介绍</p>
                            <p class="item_price" th:text="${product.getProductPrice()}">产品价格</p>
                            <p class="item_price" th:text="${product.getCount()}">产品价格</p>
                        </a>
                        <div id="car">
                            <input type="button" class="carStyle" th:onclick="'saveToCart('+${product.getProductId()}+')'" value="加入购物车"/>
                        </div>
                    </li>
                </th:block>
            </th:block>
        </ul>
    </div>
</content>
<div th:replace="mall/footer::footer-fragment"></div>
<!-- jQuery -->
<script th:src="@{/admin/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/admin/plugins/sweetalert/sweetalert.min.js}"></script>
<script th:src="@{/mall/js/search.js}" type="text/javascript"></script>
<script type="text/javascript">
    /**
     * 添加到购物车
     */
    function saveToCart(id) {
        var count = 1;
        var jqxhr;
        var data = {
            "productId": id,
            "count": count
        };
        $.ajax({
            type: 'POST',
            url: '/shop-cart',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.resultCode == 200) {
                    swal({
                        title: "添加成功",
                        text: "确认框",
                        icon: "success",
                        buttons: true,
                        dangerMode: true,
                    }).then((flag) => {
                            window.location.reload();
                        }
                    );
                } else {
                    swal(result.message, {
                        icon: "error",
                        buttons: {
                            confirm: "去登录"
                        },
                    }).then((flag) => {
                            if (flag) {
                                window.location.href = '/login';
                            }
                        }
                    );
                }
            },
            error: function () {
                swal("操作失败", {
                    icon: "error",
                });
            }
        });
    }
</script>
</body>
</html>